﻿using FittyWars.BordUtils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FittyWars.GraphicUtils
{
    public static class ImageMaker2D
    {
        public static void DrawElement(Graphics background, Element ele, float ratioWidth, float ratioHeight)
        {
            /*
            Bitmap bitmapEntity = (Bitmap)GraphicEntity.Dict[entityType].Bitmap.Clone();
            bitmapEntity.MakeTransparent(Color.FromArgb(254,254,254));
            background.DrawImage(bitmapEntity, 
                posx - GraphicEntity.Dict[entityType].Left, 
                posy - GraphicEntity.Dict[entityType].Up);
            bitmapEntity.Dispose();
            return background;
             */

            switch (ele.GameElement)
            {
                case GameElement.Shape :
                    foreach (Polygon p in ele.GetElementGeometrics())
                    {
                        Matrix mat = new Matrix();
                        // TODO change to (0.5, 0.5)
                        mat.Translate(ratioWidth / 2, ratioHeight / 2);
                        mat.Scale(ratioWidth , ratioHeight );

                        Point[] points = p.Vectors.Select(
                                v => v.ApplyMatrix(mat)
                            ).Select(
                                v => new Point(Convert.ToInt32(v.X), Convert.ToInt32(v.Y))
                            ).ToArray();
                        background.DrawPolygon(new Pen(Color.Blue), points);
                        background.DrawEllipse(new Pen(Color.Red), 
                            Convert.ToInt32((ele.Center.X - ele.Radious + 0.5f) * ratioWidth),
                            Convert.ToInt32((ele.Center.Y - ele.Radious + 0.5f) * ratioHeight), 
                            Convert.ToInt32(2 * ratioWidth * ele.Radious),
                            Convert.ToInt32(2 * ratioHeight * ele.Radious)); 
                    }
                    break;
            }
        }
    }
}
